﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;

namespace Pahan.McuFusion.Common
{
    /// <summary>
    /// The interface for the programmer classes to implement.
    /// </summary>
    public interface IProgrammer : IDisposable
    {
        /// <summary>
        /// Gets the information about the programmer.
        /// </summary>
        ProgrammerInfo Info
        {
            get;
        }

        /// <summary>
        /// Opens the programmer. This method must be called before the actual use of the programmer.
        /// </summary>
        void Open();

        /// <summary>
        /// Closes the programmer.
        /// </summary>
        void Close();

        /// <summary>
        /// Cancels the current asynchronous operation.
        /// </summary>
        /// <seealso cref="EraseMemoryAsync"/>
        /// <seealso cref="ReadMemoryAsync"/>
        /// <seealso cref="WriteMemoryAsync"/>
        void CancelAsync();
        
        /// <summary>
        /// Erases the memory. This method does not block the calling thread.
        /// </summary>
        /// <param name="memory">The memory to erase.</param>
        /// <seealso cref="AsyncCompleted"/>
        void EraseMemoryAsync(MemoryClassInfo memory);
        
        /// <summary>
        /// Reads the program memory. This method does not block the calling thread.
        /// </summary>
        /// <param name="output">Output stream.</param>
        /// <param name="memory">The memory to read.</param>
        /// <seealso cref="AsyncCompleted"/>
        void ReadMemoryAsync(Stream output, MemoryClassInfo memory);

        /// <summary>
        /// Writes the program memory. This method does not block the calling thread.
        /// </summary>
        /// <param name="input">Input stream.</param>
        /// <param name="memory">The memory to write.</param>
        /// <seealso cref="AsyncCompleted"/>
        void WriteMemoryAsync(Stream input, MemoryClassInfo memory);

        /// <summary>
        /// Raised when the asynchronous operation is completed.
        /// </summary>
        event AsyncCompletedEventHandler AsyncCompleted;

        /// <summary>
        /// Raised when the progress of an asynchronous operation is changed.
        /// </summary>
        event ProgressChangedEventHandler ProgressChanged;
    }
}
